package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.List;

public class Reduce {

    List<Integer> arrayList;

    public Reduce(List<Integer> arrayList) {
        this.arrayList = arrayList;
    }

    public int getMaximum() {
        int max=0;
        for (int i=0;i<arrayList.size()-1;i++){
            if (arrayList.get(i+1)>arrayList.get(i)){
                max=arrayList.get(i+1);
            }
        }
        return max;
    }

    public double getMinimum() {
        int min=0;
        for (int i=0;i<arrayList.size()-1;i++){
            if (arrayList.get(i+1)<arrayList.get(i)){
                min=arrayList.get(i+1);
            }
        }
        return min;
    }

    public double getAverage() {

        double total=0;
        for (int i=0;i<arrayList.size();i++){
            total=arrayList.get(i)+total;
        }
        return total/arrayList.size();
    }

    public double getOrderedMedian() {
        double num=0;
       if (arrayList.size()%2==0){
           num=(double) (arrayList.get(arrayList.size()/2-1)+arrayList.get(arrayList.size()/2))/2;
       }else {
           System.out.println("aaaa");
           num=arrayList.get(arrayList.size()/2);
       }
       return num;
    }

    public int getFirstEven() {
        int num=0;
        for (Integer i:arrayList){
            if (i%2==0){
                num=i;
                break;
            }
        }
        return num;
    }

    public int getIndexOfFirstEven() {

        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i)%2==0){
                return i;
            }

        }
        return 0;
    }

//    false
    public boolean isEqual(List<Integer> arrayList) {
        boolean b=true;
        System.out.println("aaaa"+arrayList.size());
        System.out.println("cccc"+this.arrayList.size());
        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i)!=this.arrayList.get(i) || arrayList.size()!=this.arrayList.size()){
                b=false;
            }
        }
        return b;
    }

    public Double getMedianInLinkList(SingleLink singleLink) {
        throw new NotImplementedException();
    }

    public int getLastOdd() {
        int num=0;
        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i)%2!=0){
                num=arrayList.get(i);
            }

        }
        return num;
    }

    public int getIndexOfLastOdd() {
        int num=0;
        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i)%2!=0){
                num=i;
            }

        }
        return num;
    }
}
